package com.go.struts2.action;

import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;

import javax.servlet.ServletContext;

import org.apache.struts2.StrutsStatics;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;

@SuppressWarnings("serial")
public class FileDownloadAction extends ActionSupport {

	public String getClientDisplayedFileName() throws Exception {
		String fileName = new String(
				"ClientDisplayedFileName (中文).txt".getBytes("UTF-8"),
				"ISO8859-1");
		return fileName;
	}

	public InputStream getInputStream() throws Exception {
		ServletContext sc = (ServletContext) ActionContext.getContext().get(
				StrutsStatics.SERVLET_CONTEXT);

		File downloadDir = new File(sc.getRealPath("/WEB-INF/download"));
		File downloadFile = new File(downloadDir, "download_sample.txt");

		return new FileInputStream(downloadFile);
	}
}
